package com.timedomain.him.remake.models;

import android.content.Context;

import com.timedomain.him.remake.core.ChannelCreator;
import com.timedomain.him.remake.core.SimplePlayer;
import com.timedomain.him.remake.utils.FileUtils;
import com.timedomain.him.remake.utils.TimeUtils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MorningCall {

    public int id;
    public long date;
    public String title;
    public String duration;
    public String time;
    public boolean fav;
    public String path;

    public MorningCall(long date, String title, String duration, String time, boolean fav,String path) {
        this(-1,date,title,duration,time,fav,path);
    }
    public MorningCall(int id, long date, String title, String duration, String time, boolean fav,String path) {
        this.id = id;
        this.date = date;
        this.title = title;
        this.duration = duration;
        this.time = time;
        this.fav = fav;
        this.path = path;

    }

    public static MorningCall createForPath(Context ctx,String path){
        long date = TimeUtils.getTimeStampIgnoreTimeZone();
        String title = FileUtils.getFileNameWithoutExtension(path);

        SimplePlayer simplePlayer = new SimplePlayer(ChannelCreator.FromFile(ctx,path));
        long duration_i64 = simplePlayer.getDuration();
        simplePlayer.close();
        int durationMinute = (int) (duration_i64 / 60000);
        int durationSecond = (int)((duration_i64 % 60000) / 1000);
        String duration = durationMinute+"分"+durationSecond+"秒";
        String time= new SimpleDateFormat("MM月dd日 HH:mm", Locale.US).format(new Date());
        boolean fav = false;

        return new MorningCall(date,title,duration,time,fav,path);
    }

}
